<include file="Public:header" />
<div class="page-member subpage">
    <div class="form-header">
        <div>
            <div class="line1">
                <div class="fl"><h3>维修单详情 / {$repair.no}（{$repair.wxzt}）</h3></div>
                <div class="fr hidden">
                    <form class="search-form" method="post" action="">
                        <input name="field" value="{$context.field}" type="hidden" />
                        <input name="value" value="{$context.value}" type="hidden" />
                        <input name="page" value="{$context.page}" type="hidden" />
                        <input name="order_field" value="{$context.order_field}" type="hidden" />
                        <input name="order_sort" value="{$context.order_sort}" type="hidden" />
                        <input name="offset" value="{$context.offset}" type="hidden" />
                        <input name="id" value="{$context.id}" type="hidden" />
                    </form>
                </div>
            </div>
            <div class="line2">
                <!-- 编辑按钮组 -->
                <div class="fl form-btn-group btn-group-edit">
                    <if condition="$repair.wxzt eq 等待受理">
                        <in name="$x|default='02-03-17'" value="$rightsCode">
                            <button onclick="showDialog('accept');" class="btn-save btn-highlight">受理审批</button>
                            <else />
                            <button disabled="disabled" class="btn-save btn-disable">受理审批</button>
                        </in>
                        <span>或</span>
                        <in name="$x|default='02-03-16'" value="$rightsCode">
                            <a class="linkBtn btn-abort" onclick="action_edit();" href="javascript:void(0);">编辑</a>
                            <else />
                            <a class="linkBtn btn-abort" onclick="history.back(-1);" href="javascript:void(0);">返回</a>
                        </in>
                    </if>
                    <if condition="$repair.wxzt eq 待现场勘察">
                        <in name="$x|default='02-03-18'" value="$rightsCode">
                            <button onclick="showDialog('survey');" class="btn-save btn-highlight">录入勘察数据</button>
                            <else />
                            <button disabled="disabled" class="btn-save btn-disable">录入勘察数据</button>
                        </in>
                        <span>或</span>
                        <in name="$x|default='02-03-18'" value="$rightsCode">
                            <a class="linkBtn btn-abort" onclick="action_draft();" href="javascript:void(0);">作废</a>
                            <else />
                            <button disabled="disabled" class="btn-save btn-disable">作废</button>
                        </in>
                    </if>
                    <if condition="$repair.wxzt eq 待审批">
                        <in name="$x|default='02-03-19'" value="$rightsCode">
                            <button onclick="showDialog('approve');" class="btn-save btn-highlight">维修审批</button>
                            <else />
                            <button disabled="disabled" class="btn-save btn-disable">维修审批</button>
                        </in>
                        <span>或</span>
                        <a class="linkBtn btn-abort" onclick="history.back(-1);" href="javascript:void(0);">返回</a>
                    </if>
                    <if condition="$repair.wxzt eq 待验收">
                        <in name="$x|default='02-03-20'" value="$rightsCode">
                            <button onclick="showDialog('yanshou');" class="btn-save btn-highlight">验收审批</button>
                            <else />
                            <button disabled="disabled" class="btn-save btn-disable">验收审批</button>
                        </in>
                        <span>或</span>
                        <a class="linkBtn btn-abort" onclick="history.back(-1);" href="javascript:void(0);">返回</a>
                    </if>
                </div>
                <!-- 保存按钮组 -->
                <div class="fl form-btn-group btn-group-save hidden">
                    <button onclick="action_save();" class="btn-save btn-highlight">保 存</button>
                    <span>或</span>
                    <a class="linkBtn btn-abort" onclick="action_abort();" href="javascript:void(0);">放弃</a>
                </div>
                <div class="fl form-btn-more">
                    <button class="btn-normal btn-more">
                        更多操作<i class="drop-down"></i>
                    </button>
                    <ul class="more-action hidden">
                        <in name="$x|default='02-03-16'" value="$rightsCode">
                            <li><a onclick="action_del2();" href="javascript:void(0);">删 除</a></li>
                        </in>
                    </ul>
                </div>
                <div class="fr form-search-count">
                    <span class="index">{$context.index}/{$page.total}</span>
                    <button onclick="ItemJump({$page.prev.id}, {$page.prev.offset});" class="btn-normal">上一条</button>
                    <button onclick="ItemJump({$page.next.id}, {$page.next.offset});" class="btn-normal">下一条</button>
                </div>
            </div>
        </div>
    </div>
    <div class="form-box2">
        <div style="border-bottom: 0;">
            <form id="repairForm" method="post" action="">
                <!--表单相关原始信息存储-->
                <input type="hidden" name="old_bxr" value="{$repair.bxr}" />
                <input type="hidden" name="old_bxms" value="{$repair.bxms}" />
                <input type="hidden" name="old_bxdh" value="{$repair.bxdh}" />
                <input type="hidden" name="old_bxrq" value="{$repair.bxrq}" />
                <input type="hidden" name="old_wxsf" value="{$repair.wxsf}" />
                <input type="hidden" name="old_wxdh" value="{$repair.wxdh}" />
                <input type="hidden" name="old_wxrq" value="{$repair.wxrq}" />
                <input type="hidden" name="old_wxzt" value="{$repair.wxzt}" />
                <input type="hidden" name="old_wxfy" value="{$repair.wxfy}" />
                <input type="hidden" name="old_remarks" value="{$repair.remarks}" />
                <table class="form">
                    <tr>
                        <th width="15%">维修类型<span class="hint">*</span></th>
                        <td width="35%" field="type">{$repair.type}</td>
                        <th width="15%">报修日期<span class="hint">*</span></th>
                        <td field="bxrq">{$repair.bxrq}</td>
                    </tr>
                    <tr>
                        <th>小区名称<span class="hint">*</span></th>
                        <td field="community_id">{$community[$repair[community_id]]}</td>
                        <th>房源地址<span class="hint">*</span></th>
                        <td field="house_addr">{$repair.house_addr|default='公共区域维修'}</td>
                    </tr>
                    <tr>
                        <th>报修人<span class="hint">*</span></th>
                        <td field="bxr">{$repair.bxr}</td>
                        <th>报修电话<span class="hint">*</span></th>
                        <td field="bxdh">{$repair.bxdh}</td>
                    </tr>
                    <tr style="vertical-align: top;height:60px;">
                        <th>报修描述<span class="hint">*</span></th>
                        <td field="bxms">{$repair.bxms}</td>
                        <th>备注</th>
                        <td field="remarks">{$repair.remarks}</td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div class="sub-listview" style="height:300px;">
        <ul class="ui-tabs">
            <li class="selected" target="tabs-pic">描述图片</li>
            <li target="tabs-survey">勘查详情</li>
            <li target="tabs-yanshou">验收详情</li>
            <li target="tabs-log">审批记录</li>
        </ul>
        <div class="tabs-item tabs-pic">
            <table class="form" style="margin-top:10px;">
                <tr>
                    <td colspan="4">
                        <img name="xc1_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.xc1_Img|default='__IMG__/xc1.png'}" />
                        <img name="xc2_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.xc2_Img|default='__IMG__/xc2.png'}" />
                        <img name="xc3_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.xc3_Img|default='__IMG__/xc3.png'}" />
                        <img name="xc4_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.xc4_Img|default='__IMG__/xc4.png'}" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="tabs-item tabs-survey hidden">
            <table class="form" style="margin-top:10px;margin-left:20px;">
                <tr>
                    <td colspan="4">
                        <img name="kc1_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.kc1_Img|default='__IMG__/kc1.png'}" />
                        <img name="kc2_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.kc2_Img|default='__IMG__/kc2.png'}" />
                        <img name="kc3_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.kc3_Img|default='__IMG__/kc3.png'}" />
                        <img name="kc4_Img" style="width:150px;height:120px;margin-right:20px;" class="img-small" src="{$repair.kc4_Img|default='__IMG__/kc4.png'}" />
                    </td>
                </tr>
                <tr></tr>
                <tr style="margin-left:40px;">
                    <th width="15%">勘察结论</th>
                    <td width="35%" field="survey">{$repair.survey}</td>
                    <th width="15%">勘察工作人员</th>
                    <td width="35%" field="survey_ren">{$repair.survey_ren}</td>
                </tr>
            </table>
        </div>
        <div class="tabs-item tabs-yanshou hidden">
            <table class="form" style="margin-top:10px;margin-left:20px;">
                <tr>
                    <th width="15%">总共维修费用</th>
                    <td width="35%" field="yanshou_total">{$repair.yanshou_total}</td>
                    <th width="15%">实际人工费</th>
                    <td field="yanshou_rgf">{$repair.yanshou_rgf}</td>
                </tr>
                <tr>
                    <th>实际材料费</th>
                    <td field="yanshou_clf">{$repair.yanshou_clf}</td>
                    <th>实际其他费用</th>
                    <td field="yanshou_qtf">{$repair.yanshou_qtf}</td>
                </tr>
                <tr>
                    <th>施工单位</th>
                    <td field="yanshou_sgdw">{$repair.yanshou_sgdw}</td>
                    <th>施工单位电话</th>
                    <td field="yanshou_sgdwdh">{$repair.yanshou_sgdwdh}</td>
                </tr>
                <tr>
                    <th>竣工日期</th>
                    <td field="yanshou_fdate">{$repair.yanshou_fdate}</td>
                </tr>
            </table>
        </div>
        <div class="tabs-item tabs-log hidden">
            <table class="list" style="margin-top:10px;">
                <thead>
                <tr>
                    <th>审批环节</th>
                    <th>审批状态</th>
                    <th>审批意见</th>
                    <th>审批人</th>
                    <th>审批时间</th>
                </tr>
                </thead>
                <tbody>
                <volist name="log" id="vo">
                    <tr>
                        <td>{$vo.step}</td>
                        <td>{$vo.state}</td>
                        <td>{$vo.opinion}</td>
                        <td>{$vo.cuser}</td>
                        <td>{$vo.ctime}</td>
                    </tr>
                </volist>
                </tbody>
            </table>
        </div>
    </div>
</div>
<link  href="__JS__/viewer/viewer.min.css" rel="stylesheet">
<script src="__JS__/viewer/viewer.min.js"></script>
<div class="dialog dialog-accept hidden">
    <div class="box" style="height:340px;">
        <div class="title">
            <h4 class="fl">受理审批对话框</h4>
            <span class="fr"><a href="#" onclick="closeDialog();">关闭</a></span>
        </div>
        <table class="form-tab">
            <tr>
                <th width="100">审批状态：</th>
                <td>
                    <input name="spzt" checked="checked" value="同意" type="checkbox" /><label>同意</label>
                    <input name="spzt" value="拒绝" type="checkbox" /><label>拒绝</label>
                </td>
            </tr>
            <tr>
                <th>审批意见：</th>
                <td>
                    <textarea name="spyj"></textarea>
                    <select name="opinion" target="spyj" style="margin:5px 0;">
                        <option value="">--选择常用审批意见--</option>
                        <volist name="opinion" id="vo">
                            <option value="{$vo.name}">{$vo.name}</option>
                        </volist>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;line-height:40px;">
                    <button class="btn btn-highlight" onclick="action_accept();">提交</button>
                    <span>或</span>
                    <a href="#" onclick="closeDialog();" class="linkBtn">放弃</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="dialog dialog-survey hidden">
    <div class="box" style="height: 320px;">
        <div class="title">
            <h4 class="fl">录入勘察数据对话框</h4>
            <span class="fr"><a href="#" onclick="closeDialog();">关闭</a></span>
        </div>
        <table class="form-tab">
            <tr>
                <th width="100">勘察结论：</th>
                <td><textarea name="survey" style="width:180px;height:60px;"></textarea></td>
            </tr>
            <tr>
                <th>勘察工作人员：</th>
                <td><input name="survey_ren" type="text" placeholder="必填" value="" /></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center">
                    <input name="upload" class="hidden" type="file" />
                    <input name="kc1_Img" type="hidden" value="{$repair.kc1_Img}" />
                    <input name="kc2_Img" type="hidden" value="{$repair.kc2_Img}" />
                    <input name="kc3_Img" type="hidden" value="{$repair.kc3_Img}" />
                    <input name="kc4_Img" type="hidden" value="{$repair.kc4_Img}" />
                    <img name="kc1_Img" style="width:75px;height:60px;margin-right:10px;" class="img-upload" src="{$repair.1|default='__IMG__/kc1.png'}" />
                    <img name="kc2_Img" style="width:75px;height:60px;margin-right:10px;" class="img-upload" src="{$repair.1|default='__IMG__/kc2.png'}" />
                    <img name="kc3_Img" style="width:75px;height:60px;margin-right:10px;" class="img-upload" src="{$repair.1|default='__IMG__/kc3.png'}" />
                    <img name="kc4_Img" style="width:75px;height:60px;" class="img-upload" src="{$repair.1|default='__IMG__/kc4.png'}" />
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;line-height:40px;">
                    <button class="btn btn-highlight" onclick="action_survey();">提交</button>
                    <span>或</span>
                    <a href="#" onclick="closeDialog();" class="linkBtn">放弃</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="dialog dialog-approve hidden">
    <div class="box" style="height:340px;">
        <div class="title">
            <h4 class="fl">维修审批对话框</h4>
            <span class="fr"><a href="#" onclick="closeDialog();">关闭</a></span>
        </div>
        <table class="form-tab">
            <tr>
                <th width="100">审批状态：</th>
                <td>
                    <input name="spzt" checked="checked" value="同意" type="checkbox" /><label>同意</label>
                    <input name="spzt" value="拒绝" type="checkbox" /><label>拒绝</label>
                </td>
            </tr>
            <tr>
                <th>审批意见：</th>
                <td>
                    <textarea name="spyj"></textarea>
                    <select name="opinion" target="spyj" style="margin:5px 0;">
                        <option value="">--选择常用审批意见--</option>
                        <volist name="opinion" id="vo">
                            <option value="{$vo.name}">{$vo.name}</option>
                        </volist>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;line-height:40px;">
                    <button class="btn btn-highlight" onclick="action_approve();">提交</button>
                    <span>或</span>
                    <a href="#" onclick="closeDialog();" class="linkBtn">放弃</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="dialog dialog-yanshou hidden">
    <div class="box" style="height:400px;">
        <div class="title">
            <h4 class="fl">验收审批对话框</h4>
            <span class="fr"><a href="#" onclick="closeDialog();">关闭</a></span>
        </div>
        <table class="form-tab">
            <tr>
                <th width="120">审批状态：</th>
                <td>
                    <input disabled="disabled" name="spzt" checked="checked" value="同意" type="checkbox" /><label>同意</label>
                    <input disabled="disabled" name="spzt" value="拒绝" type="checkbox" /><label>拒绝</label>
                </td>
            </tr>
            <tr>
                <th>实际人工费用：</th>
                <td><input type="text" placeholder="必填，如：0.00" name="rgf" />（元）</td>
            </tr>
            <tr>
                <th>实际材料费用：</th>
                <td><input type="text" placeholder="必填，如：0.00" name="clf" />（元）</td>
            </tr>
            <tr>
                <th>其他费用：</th>
                <td><input type="text" placeholder="必填，如：0.00" name="qtf" />（元）</td>
            </tr>
            <tr>
                <th>施工单位：</th>
                <td><input type="text" placeholder="必填" name="sgdw" /></td>
            </tr>
            <tr>
                <th>施工单位电话：</th>
                <td><input type="text" placeholder="必填" name="sgdwdh" /></td>
            </tr>
            <tr>
                <th>竣工日期：</th>
                <td><input type="text" placeholder="如：2017/10/10" name="jgrq" /></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;line-height:40px;">
                    <button class="btn btn-highlight" onclick="action_yanshou();">提交</button>
                    <span>或</span>
                    <a href="#" onclick="closeDialog();" class="linkBtn">放弃</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
    $(".img-small").viewer(); //开启图片查看器功能；

    $(document).ready(function(){
        $(".img-upload").click(function () {
            $("input[name=upload]").prop("mb", $(this).prop("name")).click();
        });
        $("input[name=upload]").change(function () {
            var self = $(this);
            var form_data = new FormData();
            var file_data = self.prop('files')[0];
            form_data.append('file', file_data);
            $.ajax({
                url: '/home/index/ajax_UploadImg',
                dataType: 'json',
                contentType: false,
                processData: false,
                data: form_data,
                type: 'post',
                success: function(res){
                    if(res.status){
                        self.val(""); //重置文件上传框
                        $("img[name="+self.prop("mb")+"]").prop("src", res.info);
                        $("input[name="+self.prop("mb")+"]").val(res.info);
                    }else{
                        alert(res.info);
                    }
                }
            });
        });
    });

    function action_yanshou(){
        var spzt = null;
        $("input[name=spzt]").each(function () {
            if($(this).prop("checked")){
                spzt = $(this).val();
            }
        });
        if(!spzt){
            alert("请填写审批状态");
            return false;
        }
        var rgf = $("input[name=rgf]").val();
        if(!rgf || isNaN(rgf)){
            alert("请填写正确的实际人工费用");
            $("input[name=rgf]").focus();
            return false;
        }
        var clf = $("input[name=clf]").val();
        if(!clf || isNaN(clf)){
            alert("请填写正确的实际材料费");
            $("input[name=clf]").focus();
            return false;
        }
        var qtf = $("input[name=qtf]").val();
        if(!qtf || isNaN(qtf)){
            alert("请填写正确的其他费用");
            $("input[name=qtf]").focus();
            return false;
        }
        var sgdw = $("input[name=sgdw]").val();
        if(!sgdw){
            alert("请填写施工单位");
            $("input[name=sgdw]").focus();
            return false;
        }
        var sgdwdh = $("input[name=sgdwdh]").val();
        if(!sgdwdh){
            alert("请填写施工单位电话");
            $("input[name=sgdwdh]").focus();
            return false;
        }
        var jgrq = $("input[name=jgrq]").val();
        if(!jgrq){
            alert("请填写竣工日期");
            $("input[name=jgrq]").focus();
            return false;
        }
        var id = $("input[name=id]").val();
        $.ajax({
            url:"/admin/repair/ajax_yanshou",
            data: {id:id, spzt:spzt, rgf:rgf,clf:clf,qtf:qtf,sgdw:sgdw,sgdwdh:sgdwdh,jgrq:jgrq},
            type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    alert("操作成功");
                    location.reload();
                }else{
                    alert(data.info);
                }
            }
        });
    }

    function action_approve(){
        var spzt = null;
        $("input[name=spzt]").each(function () {
            if($(this).prop("checked")){
                spzt = $(this).val();
            }
        });
        if(!spzt){
            alert("请填写审批状态");
            return false;
        }
        var spyj = $("textarea[name=spyj]").val();
        if(!spyj && spzt=="拒绝"){
            alert("请填写审批意见");
            return false;
        }
        var id = $("input[name=id]").val();
        $.ajax({
            url:"/admin/repair/ajax_approve",
            data: {id:id, spzt:spzt, spyj:spyj}, type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    alert("操作成功");
                    location.reload();
                }else{
                    alert(data.info);
                }
            }
        });
    }

    function action_survey(){
        var survey = $("textarea[name=survey]").val();
        if(!survey){
            alert("请填写勘察结论");
            return false;
        }
        var survey_ren = $("input[name=survey_ren]").val();
        if(!survey_ren){
            alert("请填写勘察工作人员");
            return false;
        }
        var kc1_Img = $("input[name=kc1_Img]").val();
        var kc2_Img = $("input[name=kc2_Img]").val();
        var kc3_Img = $("input[name=kc3_Img]").val();
        var kc4_Img = $("input[name=kc4_Img]").val();
        if(!kc1_Img){
            alert("请好传现场勘察图片1");
            return false;
        }
        if(!kc2_Img){
            alert("请好传现场勘察图片2");
            return false;
        }
        var id = $("input[name=id]").val();
        $.ajax({
            url:"/admin/repair/ajax_survey",
            data: {id:id, survey:survey,survey_ren:survey_ren, kc1_Img:kc1_Img, kc2_Img:kc2_Img, kc3_Img:kc3_Img, kc4_Img:kc4_Img},
            type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    alert("操作成功");
                    location.reload();
                }else{
                    alert(data.info);
                }
            }
        });
    }

    function action_accept(){
        var spzt = null;
        $("input[name=spzt]").each(function () {
            if($(this).prop("checked")){
                spzt = $(this).val();
            }
        });
        if(!spzt){
            alert("请填写审批状态");
            return false;
        }
        var spyj = $("textarea[name=spyj]").val();
        if(!spyj && spzt=="拒绝"){
            alert("请填写审批意见");
            return false;
        }
        var id = $("input[name=id]").val();
        $.ajax({
            url:"/admin/repair/ajax_accept",
            data: {id:id, spzt:spzt, spyj:spyj}, type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    alert("操作成功");
                    location.reload();
                }else{
                    alert(data.info);
                }
            }
        });
    }

    function action_draft(){
        var r=confirm("您确定要作废此维修单吗")
        if (r!=true)
        {
            return false;
        }
        var id = $("input[name=id]").val();
        $.ajax({
            url:"/admin/repair/ajax_draft",
            data: {id:id}, type:"POST", dataType:"JSON",
            success: function(data){
                if(data.status){
                    alert("操作成功");
                    location.reload();
                }else{
                    alert(data.info);
                }
            }
        });
    }
    function closeDialog(){
        $(".dialog").hide();
    }

    function showDialog(dlg){
        $(".dialog-" + dlg).show();
    }
    /**
     * 全局变量 fields  // todo
     */
    var fields = new Array("bxms", "bxr", "bxdh", "wxfy", "wxzt", "remarks");
    var options = {$options};
</script>
<script src="__JS__/repair.js?v=0.3" type="text/javascript" ></script>
<include file="Public:footer" />
